﻿using System;
using System.Collections.Generic;
using System.Text;
using NIIT.SaoBacDau.Aupi.HospitalManagement.Entities;
using System.Data.SqlClient;
using System.Data;

namespace NIIT.SaoBacDau.Aupi.HospitalManagement.DataAccess
{
    public class DAO_D_OrganizationDetails
    {
        public static List<D_OrganizationDetails> ListOrgDetails()
        {
            SqlDataAdapter sqlda = new SqlDataAdapter("Department.OrgDetailsName", DAO_ConnectDatabase.Connect());
            sqlda.SelectCommand.CommandType = CommandType.StoredProcedure;
            DataTable dtable = new DataTable();
            sqlda.Fill(dtable);
            List<D_OrganizationDetails> ListOrg = new List<D_OrganizationDetails>();
            foreach (DataRow dr in dtable.Rows)
            {
                D_OrganizationDetails org = new D_OrganizationDetails();
                org.OrganizationDetailsID = Convert.ToInt32(dr["OrganizationDetailsID"]);
                org.NameDetails = dr["NameDetails"].ToString();
                org.TypeOrganizationID = Convert.ToInt32(dr["TypeOrganizationID"]);
                ListOrg.Add(org);
            }
            return ListOrg;
        }

        public static D_OrganizationDetails OrgDs(D_OrganizationDetails OD)
        {
            SqlDataAdapter sqlda = new SqlDataAdapter("Department.OrgDetails", DAO_ConnectDatabase.Connect());
            sqlda.SelectCommand.CommandType = CommandType.StoredProcedure;
            sqlda.SelectCommand.Parameters.Add("@NameDetails", SqlDbType.NVarChar).Value = OD.NameDetails;
            DataTable dtable = new DataTable();
            sqlda.Fill(dtable);
            D_OrganizationDetails ODS = new D_OrganizationDetails();
            ODS.NameDetails = OD.NameDetails;
            ODS.OrganizationDetailsID = Convert.ToInt32(dtable.Rows[0]["OrganizationDetailsID"].ToString());
            ODS.TypeOrganizationID = Convert.ToInt32(dtable.Rows[0]["TypeOrganizationID"].ToString());
            return ODS;
        }
        public static D_OrganizationDetails OrgDepartmentName(D_OrganizationDetails OD)
        {
            SqlDataAdapter sqlda = new SqlDataAdapter("Department.OrgDepartMentName", DAO_ConnectDatabase.Connect());
            sqlda.SelectCommand.CommandType = CommandType.StoredProcedure;
            sqlda.SelectCommand.Parameters.Add("@OrganizationDetailsID", SqlDbType.NVarChar).Value = OD.OrganizationDetailsID;
            DataTable dtable = new DataTable();
            sqlda.Fill(dtable);
            D_OrganizationDetails ODS = new D_OrganizationDetails();
            ODS.NameDetails = OD.NameDetails;
            ODS.NameDetails = dtable.Rows[0]["NameDetails"].ToString();
            return ODS;
        }
    }
}
